<!DOCTYPE html >
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>商品列表</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link rel="shortcut icon" href="favicon.ico">
    <link rel="stylesheet" th:href="@{/resource/css/bootstrap.min.css}" />
    <link rel="stylesheet" th:href="@{/resource/css/font-awesome.min.css}" />
    <link rel="stylesheet" th:href="@{/resource/css/animate.css}" />
    <link rel="stylesheet" th:href="@{/resource/css/style.css}" />
    <link th:href="@{/resource/css/plugins/sweetalert/sweetalert.css}" rel="stylesheet">
    <link th:href="@{/resource/css/plugins/bootstrap-table/bootstrap-table.min.css}" rel="stylesheet">
    <link rel="stylesheet" th:href="@{/resource/css/plugins/toastr/toastr.min.css}" />

</head>

<body class="gray-bg">

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-6">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <div class="row">
                        <div class="col-sm-10">  <h5>商品管理 &nbsp;/&nbsp;  <small>选品库编辑</small></h5></div>
                        <div class="col-sm-2">
                            <button type="button"  id="back_but" class="btn btn-white">返回</button>
                        </div>
                    </div>
                </div>
                <div class="ibox-content">
                <form class="form-horizontal m-t" id="commentForm" method="post">

                <div class="form-group">
                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">名称：</label>
                            <div class="col-sm-9">
                                <p class="form-control-static" th:text="${favoritesModel.title}"></p>
                                <input id="id" type="hidden" class="form-control" name="id" required="" aria-required="true" th:value="${favoritesModel.id}">
                                <input id="cid_tv" type="hidden" class="form-control" name="roleCode" required="" aria-required="true" th:value="${favoritesModel.cid}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">主分类：</label>
                            <div class="col-sm-9">
                                <select class="form-control" name="cid" id="cid" onchange="setPid()" ></select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">小分类：</label>
                            <div class="col-sm-9">
                                <select class="form-control" name="cpid" id="cpid" ></select>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <button class="btn btn-primary" id="favorite_submit" type="button">提交</button>
                            </div>
                        </div>

                        </div>
                    </div>

                  </form>

                <!-- End Example Events -->

            </div>
        </div>
    </div>

    </div>

</div>




<div th:include="footer"></div>
<script type="text/javascript" th:src="@{/script/js/biz/product/favorite.js}"></script>

<script>

    init();
    function init() {
            $.ajax({
                url: "/common/category/categoryList",
                type: "get",
                contentType: "application/json",
                dataType:"json",
                success: function (data) {
                    var html = "";
                    for(var i=0;i<data.length;i++){
                        html = html+"<option value="+data[i].cid+">"+data[i].name+"</option>";
                    }
                    $("#cid").append(html);
                    $("#cid").val($("#cid_tv").val());
                    setPid();
                }
            });
        }

    function setPid() {
        var cpid = $("#cid").val();
        $.ajax({
            url: "/common/category/categoryItemList",
            type: "post",
            data: cpid,
            contentType: "application/json",
            dataType:"json",
            success: function (data) {
                $("#cpid").html("");
                var html = "";
                for(var i=0;i<data.length;i++){
                    html = html+"<option value="+data[i].id+">"+data[i].name+"</option>";
                }
                $("#cpid").append(html);
            }
        });
    }



    $("#favorite_submit").click(function () {
        var id = $("#id").val();
        var cid = $("#cid").val();
        var cpid = $("#cpid").val();
        var mydata = '{"id":"' + id + '","cid":"'  + cid + '","cpid":"'+cpid+'"}';
        $.ajax({
            url: "/common/product/updateFavoritesByModel",
            type: "post",
            data: mydata,
            contentType: "application/json",
            dataType:"json",
            success: function (data) {
                if(data["retType"] == "0") {
                    toastr.success("修改成功!");
                    setTimeout( "window.location.href='/common/product/doFavoriteList'",2000);//延时3秒

                } else {
                    toastr.error(data["retMsg"]);
                }
            }
        });
    });



</script>
</body>
</html>